#ifndef UPDATECHECKER_H
#define UPDATECHECKER_H

#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include "app_version.h"

class UpdateChecker : public QObject
{
    Q_OBJECT

public:
    explicit UpdateChecker(QObject *parent = nullptr);
    ~UpdateChecker();

    void checkForUpdates(bool silent = false);
    void downloadUpdate(const QString& url, const QString& md5);

signals:
    void updateAvailable(const QString& version,
                        const QString& downloadUrl,
                        const QString& releaseNotes,
                        const QString& md5,
                        const QString& fileSize);
    void noUpdateAvailable();
    void checkError(const QString& error);
    void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
    void downloadFinished(const QString& filePath);

private:
    QNetworkAccessManager* m_networkManager;
    bool m_silent;
    QString m_tempFilePath;

    void handleCheckResponse(QNetworkReply* reply);
    void handleDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
    void handleDownloadFinished();
    bool verifyMd5(const QString& filePath, const QString& expectedMd5);
    QString getOSString() const;
};

#endif // UPDATECHECKER_H 